<!DOCTYPE html>
<html lang="en">
<head>

    <title>文章管理</title>
    <th:block th:include="admin/include :: common-css" />
</head>
<body class="fixed-left">
<div id="wrapper">
    <th:block th:include="admin/include :: header-menu(3)" />

    <div class="content-page">
        <div class="content">
            <div class="container">
                <div class="row">

                        <div class="col-sm-12">
                             <h4 class="page-title">文章管理</h4>
                        </div>
                        <div class="col-md-12">
                             <table class="table table-striped table-bordered">
                                <thead>
                                <tr>
                                    <th width="35%">文章标题</th>
                                    <th width="15%">发布时间</th>
                                    <th>浏览量</th>
                                    <th>所属分类</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>

                                <tr th:each="article:${articlePage.list}">
                                    <td>
                                        <a href="/article/12" target="_blank" th:text="${article.title}" >Spring Boot 2 权威发布</a>
                                    </td>
                                    <td th:text="${article.created}">2018-12-12</td>
                                    <td th:text="${article.hits}">44</td>
                                    <td th:text="${article.categories}">默认分类</td>
                                    <td>
                                        <a th:href="${'/admin/edit/'+article.id}" class="btn btn-primary btn-sm waves-effect waves-light m-b-5">
                                            <i class="fa fa-edit"></i> <span>编辑</span>
                                        </a>
                                        <a href="javascript:void(0)" th:onclick="'delArticle('+${article.id}+')'"
                                           class="btn btn-danger btn-sm waves-effect waves-light m-b-5">
                                            <i class="fa fa-trash-o"></i> <span>删除</span></a>
                                        <a class="btn btn-warning btn-sm waves-effect waves-light m-b-5" th:href="${'/article/'+article.id}" >
                                            <i class="fa fa-rocket"></i> <span>预览</span></a>
                                    </td>

                                </tr>





                                </tbody>
                            </table>

                            <div>
                            <!--分页-->
                                <!--分页-->
                                <div class="clearfix">
                                    <ul class="pagination m-b-5 pull-right">
                                        <li>
                                            <a th:unless="${articlePage.isFirstPage}" th:href="${'?pageNum='+articlePage.prePage}" aria-label="Pre">
                                                上一页&nbsp;<i class="fa fa-angle-left"></i>
                                            </a>
                                        </li>
                                        <li th:each="num:${articlePage.navigatepageNums}" th:class="${num == articlePage.pageNum?'active':''}">
                                            <a th:href="${'?pageNum='+num}" th:text="${num}">1</a>
                                        </li>
                                        <li>
                                            <a th:unless="${articlePage.isLastPage}"  th:href="${'?pageNum='+articlePage.nextPage}" aria-label="Next">
                                                下一页&nbsp;<i class="fa fa-angle-right"></i>
                                            </a>
                                        </li>
                                        <li><span>共[[${articlePage.size}]]页</span></li>
                                    </ul>
                                </div>

                            </div>

                         </div>
                </div>
             </div>
        </div>
    </div>

</div>

   <th:block th:include="admin/include :: footer" />

    <th:block th:include="admin/include ::common-js" />
<script type="text/javascript">
    function delArticle(id) {
        if(confirm('确定删除该文章吗?')){
            $.ajax({
                type:'post',
                url : '/article/delete',
                data: {id:id},
                dataType: 'json',
                success: function (result) {
                    if (result.code==0) {
                        window.alert("文章删除成功");
                        window.location.reload();
                    } else {
                        window.alert(result.msg || '文章删除失败')
                    }
                }
            });
        }
    }

</script>

</body>
</html>